package net.flowas.genericcrud.rest;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;


//@Api(tags =  "Customization Configiration and Operation")
public class ProfileResource {
  private Map<String, Object> alias = new HashMap<>();

  /**
   * 获取js功能的插件列表.
   * @return
   */
  @GET
  @Path("plugins")
  @Produces("application/json")
  public Map<String, Object> plugins() {
    Map<String, Object> plugins = new HashMap<>();
    Map<String, Object> baseCrud = new HashMap<>();
    List<String> scrpts = new ArrayList<>();
    scrpts.add("js/baseCrud.js");
    baseCrud.put("Scripts", scrpts);
    plugins.put("baseCrud", baseCrud);
    Map<String, Object> app = new HashMap<>();
    List<String> scrptsApp = new ArrayList<>();
    scrptsApp.add("js/topMain.js");
    app.put("Scripts", scrptsApp);
    plugins.put("app", app);
    return plugins;
  }

  /**
   * 构造模型的默认填充值.
   * @param modelType 数据模型类型
   * @return
   */
  @GET
  @Path("forModel/{modelType}")
  @Produces("application/json")
  public Map<String, Object> constructSettings(
      @PathParam(CrudConstant.MODEL_TYPE) String modelType) {
    if ("OrderForm".equals(modelType)) {
      /*OrderForm of=new OrderForm(); 
      Position p=new Position(); 
      Group g=new Group(); 
      g.setId(2L);
      p.setDepartment(g); 
      of.setPosition(p); 
      alias.put("currentItem", of); */      
    }
    return alias;
  }

  /**
   * 用户登录，登录后初始化用户信息.
   */
  @PUT
  @Path("login")
  @Consumes("application/json")
  @Produces("application/json")
  // @ValidationInterceptorBinding
  public void login() {
    // AuthenticationToken authenticationToken=new UsernamePasswordToken(entity.getUsername(),
    // entity.getPassword());
    // SecurityUtils.getSubject().login(authenticationToken);
    // alias.put("operateDate", entity.getOperateDate());
    // alias.put("username", entity.getUsername());
    // User userObj = (User) SecurityUtils.getSubject().getPrincipal();
    Map<String, Object> currentItem = new HashMap<>();
    Map<String, Object> group = new HashMap<>();
    // group.put("id", userObj.getGroup().getId());
    currentItem.put("group", group);
    // alias.put("currentItem", currentItem);
    alias.put("group", group);
    // SecurityUtils.getSubject().checkPermission("hello");
  }
}
